import axios from 'axios'

const PROXY_PREFIX = '/api'

export const searchWeb = async (keyword) => {
  try {
    const response = await axios({
      method: 'get',
      url: `${PROXY_PREFIX}/baidu`, // 通过代理访问
      params: { wd: keyword }
    })
    return response.data
  } catch (error) {
    console.error('搜索请求失败:', error)
    throw new Error('搜索服务暂不可用')
  }
}

// 新增古诗文网API请求
const GUSHIWEN_API = '/api/gushiwen'

export const searchAncientPoetry = async (keyword) => {
  try {
    const response = await axios.get('http://localhost:3001/mock/gushiwen', {
      params: { search: encodeURIComponent(keyword) }
    })
    return response.data
  } catch (error) {
    console.error('古诗文API请求失败:', error)
    throw new Error('古诗文服务暂不可用')
  }
}